package contegor.scire.structure;

import contegor.scire.core.Container;
import contegor.scire.core.IdFragment;
import contegor.scire.core.MissingElementException;
import contegor.scire.core.ReturnPoint;
import contegor.scire.core.Task;
import contegor.scire.core.Version;

/**
 * Transient and synchronous {@link ConceptCloud} implementation.
 *
 * @version $Revision$
 * @author  Héctor Cirbián Pousa ($Author$)
 */
@Version("$Id$")
public class TransientSynchronousConceptCloud extends AbstractConceptCloud {

  public TransientSynchronousConceptCloud(IdFragment rootId) {
    super();
    this.root = new CloudRootContainerImpl(System.currentTimeMillis(), null, rootId);
  }

  @Override
  public <T> void process(Task<T> task, ReturnPoint<? super T> rp) {
    if (this.root.getId().sameRoot(task.getTargetContainerId())) {
      Container container = find(task.getTargetContainerId());
      if (container != null) {
        container.process(task, rp);
        return;
      }
    }
    rp.manage(task.getTaskId(), new MissingElementException("Can't find target container: " + task.getTargetContainerId()));
    rp.finish(task.getTaskId());
  }
}
